

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <style type="text/css">
        .nianli{
            border: 2px solid red;
            display: grid; /*网格布局*/
            grid-template-columns: repeat(6,auto); /*一行元素的个数，宽度auto*/
            gap: 10px;  /*容器内各个子元素之间的间距 */
            padding: 10px; /*内边距*/
        }
        .data{
            display: grid;
            grid-template-columns: repeat(7,auto);
        }
        .data > div{
            /*border: 1px solid #ddd;*/
            text-align: center;
        }
        .yueli{
            border: 1px solid blue;
            padding: 5px;
        }
        .yue{
            color: red;
            font-weight: bold;
            text-align: center;
            line-height: 2;
        }
        .title{
            text-align: center;
            font-size: 24px;
            font-weight: bold;
            line-height: 2;
            color: red;
        }
        select{
            width: 160px;
            padding: 8px;
        }
    </style>
    <title>年历</title>
</head>
<body>
<script>
    function nav(value){
        console.log(value,location.href)//列表框当前选项的值及当前页面的网址
        location.href="?year="+value
    }
</script>
<?php
$now = new DateTime();//当前的日期时间
$currentYear=$now->format("Y");//当前的年份
$year = $_GET['year']??$currentYear;//显示年历的年份
?>
<div class='kuang'>
    <select onchange="nav(value)">
        <?php
        for ($i=$currentYear;$i>$currentYear-10;--$i){
            echo "           <option ",$i==$year?"selected ":"","value='", $i, "'>", $i,  "</option>\n";
        }
        ?>
    </select>
    <div class="title"><?=$year?>年</div>
    <div class="nianli"><?php
        for ($m=1;$m<=12;$m++){
            echo "<div class='yueli'>";
            echo "<div class='yue'>{$m}月</div>";
            echo "<div class='data'>";
            echo "<div>一</div><div>二</div><div>三</div><div>四</div><div>五</div><div>六</div><div>日</div>";
            $d=new DateTime("$year-$m-1");
            $kong=$d->format('N')-1;
            echo str_repeat("<div></div>",$kong);
            $days=$d->format('t');//天数
            for ($i=1;$i<=$days;$i++){
                echo "<div>$i</div>";
            }
            echo "</div></div>";
        }
        ?>

    </div>
</div>
</body>
</html>
